# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=imagemagick

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.8.9.1
pkgrel=1
pkgdesc="An image viewing/manipulation program (mingw-w64)"
arch=('any')
url="http://www.imagemagick.org/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config"
            "${MINGW_PACKAGE_PREFIX}-pango"
            "${MINGW_PACKAGE_PREFIX}-cairo"
            "${MINGW_PACKAGE_PREFIX}-openexr"
            "${MINGW_PACKAGE_PREFIX}-librsvg"
            "${MINGW_PACKAGE_PREFIX}-libxml2"
            "${MINGW_PACKAGE_PREFIX}-jasper"
            "${MINGW_PACKAGE_PREFIX}-libpng"
            "${MINGW_PACKAGE_PREFIX}-libtiff"
            "${MINGW_PACKAGE_PREFIX}-libwebp")
depends=("${MINGW_PACKAGE_PREFIX}-libtool"
        "${MINGW_PACKAGE_PREFIX}-djvulibre"
        "${MINGW_PACKAGE_PREFIX}-lcms2"
        "${MINGW_PACKAGE_PREFIX}-fontconfig"
        "${MINGW_PACKAGE_PREFIX}-freetype"
        "${MINGW_PACKAGE_PREFIX}-bzip2"
        "${MINGW_PACKAGE_PREFIX}-zlib"
        "${MINGW_PACKAGE_PREFIX}-liblqr"
        "${MINGW_PACKAGE_PREFIX}-fontconfig"
        "${MINGW_PACKAGE_PREFIX}-xz"
        "${MINGW_PACKAGE_PREFIX}-glib2"
        "${MINGW_PACKAGE_PREFIX}-fftw"
        "${MINGW_PACKAGE_PREFIX}-openjpeg2"
        #"${MINGW_PACKAGE_PREFIX}-perl"
        )
optdepends=("${MINGW_PACKAGE_PREFIX}-ghostscript: for Ghostscript support"
      "${MINGW_PACKAGE_PREFIX}-openexr: for OpenEXR support"
      "${MINGW_PACKAGE_PREFIX}-librsvg: for SVG support"
      "${MINGW_PACKAGE_PREFIX}-libxml2: for XML support"
      "${MINGW_PACKAGE_PREFIX}-jasper: for JPEG-2000 support"
      "${MINGW_PACKAGE_PREFIX}-libpng: for PNG support"
      "${MINGW_PACKAGE_PREFIX}-libtiff: for PNG support"
      "${MINGW_PACKAGE_PREFIX}-libwebp: for WEBP support")
options=('staticlibs' 'strip')
source=(ftp://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/ImageMagick-${pkgver%.*}-${pkgver##*.}.tar.xz{,.asc}
        ImageMagick-6.8.8.1-mingw.patch
        winpath.patch)
md5sums=('bde038ae05fb20d29cebf88ab9cbdce5'
         'SKIP'
         '7ecd727d1d9baad5f9b41ebcb2facdbe'
         'b0b634231da667d7472522fc08fd3519')

prepare() {
  cd ImageMagick-${pkgver%.*}-${pkgver##*.}
  patch -p1 -i ${srcdir}/ImageMagick-6.8.8.1-mingw.patch
  patch -p1 -i ${srcdir}/winpath.patch
  autoreconf -fi
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cd ImageMagick-${pkgver%.*}-${pkgver##*.}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}  
  [[ $CARCH = "i686" ]] && EXTRAOPTS="--with-gcc-arch=i686"
  [[ $CARCH = "x86_64" ]] && EXTRAOPTS="--with-gcc-arch=x86-64"
  ../configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-modules \
    --enable-hdri \
    --with-wmf \
    --with-openexr \
    --with-xml \
    --with-lcms2 \
    --with-openjp2 \
    --with-lqr \
    --with-webp \
    --with-rsvg \
    --with-gslib \
    --without-gvc \
    --with-djvu \
    --without-autotrace \
    --without-jbig \
    --without-fpx \
    --without-dps \
    --with-fftw \
    --without-perl \
    --without-x \
    $EXTRAOPTS
    make
  
    #--enable-opencl \
    #--with-gslib \
    #--with-gs-font-dir=/usr/share/fonts/Type1 
    #--with-perl-options="INSTALLDIRS=vendor"    
}

package() {
  cd ImageMagick-${pkgver%.*}-${pkgver##*.}/build-${MINGW_CHOST}
  make -j1 DESTDIR="${pkgdir}" install
  #make DESTDIR="${pkgdir}" install-data-html
  install -Dm644 ${srcdir}/ImageMagick-${pkgver%.*}-${pkgver##*.}/LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 ${srcdir}/ImageMagick-${pkgver%.*}-${pkgver##*.}/NOTICE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/NOTICE"

  #rm -r "${pkgdir}${MINGW_PREFIX}/share"
}
